package dao

import (
	"album/model"
	"context"
	"listenboos-common/db"
	"listenboos-common/db/gorms"
)

type BaseCategory1Dao struct {
	conn *gorms.GormConn
}

func NewBaseCategory1Dao(db *db.ListenDB) *BaseCategory1Dao {
	return &BaseCategory1Dao{
		conn: gorms.New(db.Conn),
	}
}
func (u *BaseCategory1Dao) FindCategory1ById(ctx context.Context, id int64) (category1 *model.BaseCategory1, err error) {
	session := u.conn.Session(ctx)
	err = session.Model(&model.BaseCategory1{}).Where("id = ?", id).First(&category1).Error
	if err != nil {
		return nil, err
	}
	return category1, nil

}
func (u *BaseCategory1Dao) FindByCategory1(ctx context.Context, category1Id int64) (category1s []*model.BaseCategory1, err error) {
	session := u.conn.Session(ctx)
	if category1Id != 0 {
		err = session.Model(&model.BaseCategory1{}).Where("id = ?", category1Id).Find(&category1s).Error
	} else {
		err = session.Model(&model.BaseCategory1{}).Find(&category1s).Error
	}
	if err != nil {
		return nil, err
	}
	return category1s, nil
}
func (u *BaseCategory1Dao) FindByCategory1ById(ctx context.Context, category1Id int64) (category1 *model.BaseCategory1, err error) {
	session := u.conn.Session(ctx)
	err = session.Model(&model.BaseCategory1{}).Where("id = ?", category1Id).First(&category1).Error
	if err != nil {
		return nil, err
	}
	return category1, nil
}
